# -*- coding: utf-8 -*-
# @Author: XiaoRui
# @FileName: NODE.py
# @Time: 2021/4/20 15:49
# @Software: PyCharm

import numpy as np

nodeNum = 0


# 判断节点的osm_id位于哪个区间段
def which_interval(road_id):
    # temp = road_id // 100
    # if temp >= 6:
    #     return 6
    # else:
    #     return temp
    if 100 >= road_id >= 0:
        return 0
    elif 200 >= road_id >= 101:
        return 1
    elif 300 >= road_id >= 201:
        return 2
    elif 400 >= road_id >= 301:
        return 3
    elif 500 >= road_id >= 401:
        return 4
    elif 600 >= road_id >= 501:
        return 5
    else:
        return 6


class Node(object):
    def __init__(self, Obj, coordinates, next_coordinates):
        # node number
        global nodeNum
        self.nodeName = nodeNum
        nodeNum += 1
        # read roadLines properties
        self.road_osm_id = []
        self.road_osm_id.append(int(Obj["properties"]["osm_id"]))
        self.road_name = Obj["properties"]["NAME"]
        # road type serial number
        self.road_type = float(Obj["properties"]["TYPE"])
        self.road_wide = []
        self.road_wide.append(float(Obj["properties"]["WIDE"]))
        self.road_spide = []
        self.road_spide.append(float(Obj["properties"]["SPIDE"][0:2]))
        self.road_length = float(Obj["properties"]["LENGTH"])
        # road type
        self.road_rtype = Obj["properties"]["RTYPE"]
        # road area
        self.road_shapeLeng = Obj["properties"]["Shape_Leng"]
        # node coordinates
        self.node_coordinates = coordinates
        # 如果下一个节点不为空就作为此节点的子节点
        if next_coordinates:
            self.node_childrenNodes = []
            self.node_childrenNodes.append(next_coordinates)
            self.node_childrenNames = []
            self.node_childrenNames.append(nodeNum)
        else:
            self.node_childrenNodes = []
            self.node_childrenNames = []
